package com.fengye.middleware.rabbitmq.boot.demo.object;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 *
 * @author sky
 * @date 2021年06月09日 12:55 下午
 */
@Component
public class ObjectConfig {

    @Value("${mq.object.info.queue.name:object_queue_name}")
    private String objectQueueName;

    @Value("${mq.object.info.exchange.name:object_change_name}")
    private String objectExchangeName;

    @Value("${mq.object.info.routing.key.name:object_routing_key_name}")
    private String objectRoutingKeyName;

    /* 创建简单消息模型：队列、交换机和路由 */

    // 队列
    @Bean(name = "objectQueue")
    public Queue objectQueue(){
        return new Queue(objectQueueName);
    }

    @Bean(name = "objectExchange")
    public DirectExchange objectExchange(){
        return new DirectExchange(objectExchangeName, true, false);
    }

    @Bean
    public Binding objectBinding(){
        return BindingBuilder.bind(objectQueue()).to(objectExchange()).with(objectRoutingKeyName);
    }
}
